package org.keyroy.mapEditor.ui.dialogs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

public class ThreadDialog extends Shell {
	private Label lblNewLabel;
	private ProgressBar progressBar;

//	/**
//	 * Launch the application.
//	 * 
//	 * @param args
//	 */
//	public static void main(String args[]) {
//		try {
//			Display display = Display.getDefault();
//			ThreadDialog shell = new ThreadDialog(display);
//			shell.open();
//			shell.layout();
//			while (!shell.isDisposed()) {
//				if (!display.readAndDispatch()) {
//					display.sleep();
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public ThreadDialog(Shell display) {
		super(display.getDisplay(), SWT.TITLE);
		setLayout(new FormLayout());

		progressBar = new ProgressBar(this, SWT.NONE);
		FormData fd_progressBar = new FormData();
		fd_progressBar.right = new FormAttachment(0, 384);
		fd_progressBar.top = new FormAttachment(0, 33);
		fd_progressBar.left = new FormAttachment(0, 10);
		progressBar.setLayoutData(fd_progressBar);

		lblNewLabel = new Label(this, SWT.BORDER | SWT.SHADOW_IN);
		FormData fd_lblNewLabel = new FormData();
		fd_lblNewLabel.bottom = new FormAttachment(0, 27);
		fd_lblNewLabel.right = new FormAttachment(0, 384);
		fd_lblNewLabel.top = new FormAttachment(0, 10);
		fd_lblNewLabel.left = new FormAttachment(0, 10);
		lblNewLabel.setLayoutData(fd_lblNewLabel);
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SWT Application");
		setSize(400, 88);
	}

	public final void setValue(int value) {
		progressBar.setSelection(value);
	}

	public final void setMessage(String text) {
		lblNewLabel.setText(text);
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

	protected Label getLblNewLabel() {
		return lblNewLabel;
	}

	protected ProgressBar getProgressBar() {
		return progressBar;
	}
}
